#include <bits/stdc++.h>
using namespace std;
#define ll long long

int jjpow(int, int);
int jjC(ll, ll);

const int MOD = 1e9 + 7;

int s, t, op, step;
int refer[100], dp[100];
int ret1, ret2;

void solve(){
    int d = t - s;
    while(d != 0){
        int choose = -1, jjmin =INT_MAX;
        for(int i = 1; i <= 24; ++i){
            if(abs(dp[i]) <= abs(d) && abs(dp[i] - d) < jjmin){
                jjmin = abs(dp[i] - d);
                choose = i;
            }
        }
        ret1 += choose;
        d -= dp[choose];
        if(d) ret1++;
        /* printf("choose = %d, d = %d\n", choose, d); */
        /* getchar(); */
    }
    d = t - s;
    while(d != 0){
        int choose = -1, jjmin =INT_MAX;
        for(int i = 1; i <= 24; ++i){
            if(abs(dp[i] - d) < jjmin){
                jjmin = abs(dp[i] - d);
                choose = i;
            }
        }
        ret2 += choose;
        d -= dp[choose];
        if(d) ret2++;
        /* printf("choose = %d, d = %d\n", choose, d); */
        /* getchar(); */
    }
    printf("%d\n", min(ret1, ret2));
}

void init(){
    scanf("%d%d", &s, &t);
    op = 1; step = 1; 
    for(int i = 1; i <= 24; ++i){
        refer[i] = op * step;
        op *= -1;
        step *= 2;
    }
    dp[0] = 0;
    for(int i = 1; i <= 24; ++i){
        dp[i] = dp[i - 1] + refer[i];
        /* printf("%d ", refer[i]); */
        /* printf("%d ", dp[i]); */
    }
    /* printf("\n"); */
    op = 1; step = 1;
}

int main(){
    #ifndef ONLINE_JUDGE
        auto start_clock = clock();
        //freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    #endif
    
    init();
    solve();
    
    #ifndef ONLINE_JUDGE
        auto end_clock = clock();
        //cout<<"runtime: "<<end_clock - start_clock<<"ms"<<endl;
    #endif
    return 0;
}

int jjpow(int a, int b){
    if(b == 2)return (a * a)%MOD;
    if(b == 1)return a;
    int ret1 = a, ret2 = a;
    int cnt1 = log(b)/log(2);
    int cnt2 = b - pow(2, cnt1);
    ret1 = jjpow(a, cnt2);
    for(int i = 0; i < cnt1; ++i){
        ret2 = (ret2 * ret2)%MOD;
    }
    return (ret1 * ret2)%MOD;
}

int jjC(ll a, ll b){
    int ret = 1, tmp = 1;
    for(int i = a; i > a - b; --i){
        ret = (ret * i)%MOD;
    }
    for(int i = 2; i <= b; ++i){
        tmp = (tmp * i)%MOD;
    }
    printf("%d %d\n", ret, tmp);
    return ret/tmp;
}
